package com.skplanet.rade.domain;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;

import org.codehaus.jackson.annotate.JsonIgnore;

import com.google.gson.annotations.Expose;

@Entity
@Table( name = "user" )
public class User{

	public final static String PREFIX_NUMBER_USERID = "1";
	

	public User(){
		this.setCreateDate(new Date());
		this.setUpdateDate(new Date());
	}

	public User(long id) {
		this.id = id;
	}
	/**
	 *  기본정보
	 */
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Expose
	private long id;

	@Column( name="email", unique=true )
	@Expose
	private String email;
	
	@Column( name="name", length=50 )
	private String name;

	
	@Column( name="nickname", length=50 )
	@Expose
	private String nickname;

	@Column( name="password", length=64 )
	@JsonIgnore
	private String password;

	@Column( name="salt", length=64 )
	@JsonIgnore
	private String salt;

	@Column(name = "authority")
	private String authority;

	@Column(name = "create_date")
	private Date createDate;
	
	@Column(name = "update_date")
	protected Date updateDate;
	
	@OneToMany(mappedBy = "user", fetch = FetchType.LAZY, cascade = {CascadeType.ALL})
	@OrderBy("utid ASC" )
	private List<UserTag> userTags;
	
	@OneToMany(mappedBy = "user", fetch = FetchType.LAZY, cascade = {CascadeType.ALL})
	@OrderBy("sid ASC" )
	private List<Story> stories;
	
	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	
	
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getNickname() {
		return nickname;
	}

	public void setNickname(String nickname) {
		this.nickname = nickname;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getSalt() {
		return salt;
	}

	public void setSalt(String salt) {
		this.salt = salt;
	}
	public Date getCreateDate() {
		return createDate;
	}

	public void setCreateDate(Date createDate) {
		this.createDate = createDate;
	}

	public Date getUpdateDate() {
		return updateDate;
	}

	public void setUpdateDate(Date updateDate) {
		this.updateDate = updateDate;
	}

	public String getAuthority() {
		return authority;
	}

	public void setAuthority(String authority) {
		this.authority = authority;
	}

	public List<UserTag> getUserTags() {
		return userTags;
	}

	public void setUserTags(List<UserTag> userTags) {
		this.userTags = userTags;
	}

	public void addUserTag(UserTag usertag){
		if(userTags == null){
			userTags = new ArrayList<UserTag>();
		}
		userTags.add(usertag);
	}

	public List<Story> getStories() {
		return stories;
	}

	public void setStories(List<Story> stories) {
		this.stories = stories;
	}
	
	public void addStory(Story story){
		if(stories == null){
			stories = new ArrayList<Story>();
		}
		stories.add(story);
	}	
}